import axios from "axios";
import { RequestConfig } from "../../interface/config/requestConfig";
import { ResDto } from "lh-hooks";
/**
 * 请求拦截器
 */
axios.interceptors.request.use((config: any) => {
    //config.headers = { "Content-Type": "application/x-www-form-urlencoded",  ...config.headers };
    config.headers = { "Content-Type": "application/json", ...config.headers};
    return config;
}, (err: any) => {
    return Promise.reject(err);
});
/**
 * 响应拦截器
 */
axios.interceptors.response.use((response: any): Promise<ResDto<any>> => {
    return response.data;
}, (err: any) => {
    return Promise.reject(err);
});
/**
 * 请求
 */
 export const request = (config: RequestConfig) => {
    const params = {
        headers: config.headers || {},
        method: config.method || "post",
        data: config.data || {},
        url: config.url || ""
    }
    return axios(params).catch((err: any) => err);
}